package lwx.thread;

import org.w3c.dom.ls.LSOutput;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

/**
 * @author liuwanxu
 * @date 2025/8/13 15:32
 */
public class ThreadPoolDemo {
    public static void main(String[] args) {
        ExecutorService executor = Executors.newFixedThreadPool(3);
        // 提交runnable任务
        executor.execute(()->{
            System.out.println("Runnable:" + Thread.currentThread().getName());
        });
        // 提交callable任务
        Future<String> call = executor.submit(() -> "callable");
        try{
            System.out.println(call.get());
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            // 关闭线程池
            executor.shutdown();
        }
    }
}
